package com.parfinex.sims.dao;

import com.parfinex.sims.entity.User;
import com.parfinex.sims.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * Description:实现一个userLogin的操作
 *
 * @author lijh
 * @version 1.0
 * @date 2021-11-15 11:19
 */
public class UserDaoImp implements UserDao {

    /** 查询数据库里的用户名和密码，用来跟前端输入的用户名和密码进行配对
     * @param user*/

    @Override
    public User userLogin(User user) throws SQLException {
        //1.获取一个QueryRunner对象
        QueryRunner queryRunner = new QueryRunner(DruidUtils.dataSource);
        //2.编写SQL语句
        String sql = "select user_name AS userName,user_password AS password from sys_user where user_name= ? and user_password= ?";
        //3.执行查询
        User queryUser = queryRunner.query(sql, new BeanHandler<User>(User.class),user.getUserName(),user.getPassword());
        System.out.println("获取到的queryUser是：" + queryUser + "。获取到的userName是：" + queryUser.getUserName() + "。获取到的password是：" + queryUser.getPassword());
        return queryUser;
    }
}
